package com.baidu.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.baidu.entity.PageResult;
import com.baidu.entity.QueryPageBean;
import com.baidu.entity.Result;
import com.baidu.pojo.HealthPlan;
import com.baidu.service.HealthPlanService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/healthPlan")
public class HealthPlanController {

	@Reference
	private HealthPlanService healthPlanService;

//查
	@RequestMapping("/pageQuery")
	public PageResult pageQuery(@RequestBody QueryPageBean queryPageBean){
		PageResult pageResult = healthPlanService.pageQuery(queryPageBean);
		return pageResult;

	}


//删
	@DeleteMapping("/delete/{id}")
	public Result delete(@PathVariable Integer id){

		try {
			healthPlanService.delete(id);
			return new Result(true, "删除成功");
		} catch (Exception e) {
				return  new Result(false,"删除失败");
		}


	}

//添加
	@RequestMapping("/add")
	public Result add(@RequestBody HealthPlan healthPlan) {//传递过来的是json、对象

		try {
			healthPlanService.add(healthPlan);
			return 	new Result(true, "添加成功");

		} catch (Exception e) {
			return 	new Result(false, "添加失败");
		}


	}

//	回显单个
@GetMapping("/findById/{id}")
public Result findById(@PathVariable Integer id){
	try {
		HealthPlan healthPlan= healthPlanService.findById(id);
		return new Result(true,"",healthPlan);
	} catch (Exception e) {
		return new Result(false,"");
	}
}

//编辑
@PostMapping("/edit")
public Result editCheckItem(@RequestBody HealthPlan healthPlan){

	try {
		healthPlanService.edit(healthPlan);
		return new Result(true, "编辑成功");
	} catch (Exception e) {
		return new Result(false,"编辑失败");
	}


}




}
